home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Components / Microsoft ASP / _SETUP.1 / ASPWizard.jar / asp / wizard / def / DefQuery.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-20  |  4.8 KB  |  178 lines

  1. package asp.wizard.def;
  2.  
  3. import asp.wizard.AspWizardExceptionHandler;
  4. import asp.wizard.EWizDbManager;
  5. import asp.wizard.WizDbManager;
  6. import java.sql.ResultSet;
  7. import java.sql.ResultSetMetaData;
  8. import java.sql.SQLException;
  9. import java.util.Vector;
  10.  
  11. public class DefQuery extends DefAbstract {
  12.    private DefConnection _defConnection;
  13.    private String _dbConnection;
  14.    private int _usePreviousQuery = 1;
  15.    private String _select;
  16.    private String _from;
  17.    private String _where;
  18.    private String _orderBy;
  19.    private Vector _firstRecord;
  20.    private Vector _resultSetColumns;
  21.  
  22.    public void setResultSet(ResultSet resultSet) {
  23.       if (resultSet != null) {
  24.          Vector firstRec = new Vector();
  25.  
  26.          try {
  27.             ResultSetMetaData rsmd = resultSet.getMetaData();
  28.             if (resultSet.next()) {
  29.                int cols = rsmd.getColumnCount();
  30.  
  31.                for(int i = 1; i <= cols; ++i) {
  32.                   firstRec.addElement(resultSet.getObject(i));
  33.                }
  34.             }
  35.  
  36.             this.setFirstRecord(firstRec);
  37.             this._resultSetColumns = WizDbManager.getResultSetColumnInfosFrom(resultSet);
  38.             resultSet.close();
  39.          } catch (SQLException e) {
  40.             AspWizardExceptionHandler.showMessage(0, ((Throwable)e).getMessage());
  41.          } catch (EWizDbManager e) {
  42.             AspWizardExceptionHandler.showMessage(0, ((Throwable)e).getMessage());
  43.          }
  44.  
  45.       }
  46.    }
  47.  
  48.    private void setFirstRecord(Vector record) {
  49.       this._firstRecord = record;
  50.    }
  51.  
  52.    public Vector getFirstRecord() {
  53.       return this._firstRecord;
  54.    }
  55.  
  56.    public DefQuery() {
  57.    }
  58.  
  59.    public DefQuery(DefQuery aDefQuery) {
  60.       this._defConnection = aDefQuery._defConnection;
  61.       this._dbConnection = aDefQuery._dbConnection;
  62.       this._usePreviousQuery = aDefQuery._usePreviousQuery;
  63.       this.setEqualSqlStatementTo(aDefQuery);
  64.    }
  65.  
  66.    public void setEqualSqlStatementTo(DefQuery aDefQuery) {
  67.       this._select = aDefQuery._select;
  68.       this._from = aDefQuery._from;
  69.       this._where = aDefQuery._where;
  70.       this._orderBy = aDefQuery._orderBy;
  71.    }
  72.  
  73.    public void setDefConnection(DefConnection defConnection) {
  74.       this._defConnection = defConnection;
  75.    }
  76.  
  77.    public DefConnection getDefConnection() {
  78.       return this._defConnection;
  79.    }
  80.  
  81.    public void setDBConnection(String dbConnection) {
  82.       this._dbConnection = dbConnection;
  83.    }
  84.  
  85.    public void setUsePreviousQuery(int usePreviousQuery) {
  86.       this._usePreviousQuery = usePreviousQuery;
  87.    }
  88.  
  89.    public void setSelect(String select) {
  90.       this._select = select.trim();
  91.    }
  92.  
  93.    public void setFrom(String from) {
  94.       this._from = from.trim();
  95.    }
  96.  
  97.    public void setWhere(String where) {
  98.       this._where = where.trim();
  99.    }
  100.  
  101.    public void setOrderBy(String orderBy) {
  102.       this._orderBy = orderBy.trim();
  103.    }
  104.  
  105.    public int getUsePreviousQuery() {
  106.       return this._usePreviousQuery;
  107.    }
  108.  
  109.    public String getSelect() {
  110.       return this._select;
  111.    }
  112.  
  113.    public String getFrom() {
  114.       return this._from;
  115.    }
  116.  
  117.    public String getWhere() {
  118.       return this._where;
  119.    }
  120.  
  121.    public String getOrderBy() {
  122.       return this._orderBy;
  123.    }
  124.  
  125.    public String getDBConnection() {
  126.       return this._dbConnection;
  127.    }
  128.  
  129.    public String getSql() {
  130.       StringBuffer sb = new StringBuffer();
  131.       if (this.getSelect() != null && !this.getSelect().equals("")) {
  132.          sb.append("SELECT ");
  133.          sb.append(this.getSelect());
  134.       }
  135.  
  136.       if (this.getFrom() != null && !this.getFrom().equals("")) {
  137.          if (sb.length() > 0) {
  138.             sb.append(" ");
  139.          }
  140.  
  141.          sb.append("FROM ");
  142.          sb.append(this.getFrom());
  143.       }
  144.  
  145.       if (this.getWhere() != null && !this.getWhere().equals("")) {
  146.          if (sb.length() > 0) {
  147.             sb.append(" ");
  148.          }
  149.  
  150.          sb.append("WHERE ");
  151.          sb.append(this.getWhere());
  152.       }
  153.  
  154.       if (this.getOrderBy() != null && !this.getOrderBy().equals("")) {
  155.          if (sb.length() > 0) {
  156.             sb.append(" ");
  157.          }
  158.  
  159.          sb.append("ORDER BY ");
  160.          sb.append(this.getOrderBy());
  161.       }
  162.  
  163.       return sb.toString();
  164.    }
  165.  
  166.    public String getBaseName() {
  167.       return "MSDBQuery";
  168.    }
  169.  
  170.    public Vector getResultSetColumnInfos() {
  171.       return this._resultSetColumns;
  172.    }
  173.  
  174.    public boolean equalSqlStatementTo(DefQuery otherQuery) {
  175.       return this._select.equals(otherQuery.getSelect()) && this._from.equals(otherQuery.getFrom()) && this._where.equals(otherQuery.getWhere()) && this._orderBy.equals(otherQuery.getOrderBy());
  176.    }
  177. }
  178.